



exports.array_proto			= Array.prototype;
exports.obj_proto			= Object.prototype;
exports.slice				= Array.prototype.slice;
exports.has_own_property		= exports.obj_proto.hasOwnProperty;
exports.native_for_each		= exports.array_proto.forEach;
exports.breaker			= {};



/*
* extract Parameter from the URI
*
*@param	uri 		The URI to be checked
*@param	parameter 	The Parameter to be found
*@return 			Value of the Parameter or FALSE
*
*/
exports.extract_parameter = function (uri, parameter) {
	if (!uri) {
		return;
	}
	var uri		= uri.split('#')[0];
	var parts	= uri.split('?');

	if (parts.length == 1) {
		return false;
	}

	var query	= decodeURI(parts[1]).replace(';', '&');
	parameter	+= '=';
	var params	= query.split('&');

	for (var i = 0, param; param = params[i]; ++i) {
		if (param.indexOf(parameter) === 0) {
			return unescape(param.split('=')[1]);
		}
	}

	return false;
};



/*
 * curtsey to underscrore.js
 *
 * The cornerstone, an each implementation, aka forEach.
 * Handles objects with the built-in forEach, arrays, and raw objects.
 * Delegates to ECMAScript 5's native forEach if available.
 */
exports.each = function(obj, iterator, context) {
	if (obj == null) return;
	if (exports.native_for_each && obj.forEach === exports.native_for_each) {
		obj.forEach(iterator, context);
	} else if (obj.length === +obj.length) {
		for (var i = 0, l = obj.length; i < l; i++) {
			if (i in obj && iterator.call(context, obj[i], i, obj) === exports.breaker) return;
		}
	} else {
		for (var key in obj) {
			if (exports.has_own_property.call(obj, key)) {
				if (iterator.call(context, obj[key], key, obj) === exports.breaker) return;
			}
		}
	}
};



/*
 * curtsey to underscrore.js
 *
 * Extend a given object with all the properties in passed-in object(s).
 */
exports.extend = function(obj) {
	exports.each(exports.slice.call(arguments, 1), function(source) {
		for (var prop in source) {
			if (source[prop] !== void 0) obj[prop] = source[prop];
		}
	});
	return obj;
};



/*
 * return global options objekt, in case default is set, override default with global options
 */
exports.get_global_options = function(default_options){
	return exports.extend(default_options||{}, exports.options);
}

/*
 * hesitate the callback function untill its not called again for a certain time
 */
exports.hesitate = function(callback, options){

	//if options is unset get it some nice clean empty object
	options			= options || {};

	var delay		= options.delay || 250
	, once			= options.once || false
	, args			= options.args || []
	, context		= options.context
	, handler		= null;

	//call initially once then start hesitation
	if(once){
		callback.apply(context, args);
	}

	//returns function that will call the callback after hesitation was successfully completed
	//if this function gets called with "FALSE" it kills the hesitation process without ever calling the function
	return function(immediately){
		clearTimeout(handler);
		if(immediately !== false){
			if(immediately === true){
				return callback.apply(context, args);
			}
			else{
				handler = setTimeout(function(){
					callback.apply(context, args);
				}, delay);
			}
		}
	}
}

